//用户所持代金券
exports.organization_video_course = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;
    //获取经度
    var lat = restfulParams.lat;
    //获取纬度
    var lng = restfulParams.lng;


    //最终结果
    var resultData = {};

    //任务流创建
    async.waterfall([
            //1.机构视频课
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.organization_video_course + "/vc_id/"+restfulParams.vc_id,
                        method: 'GET',
                        /*data: {
                            fields: ["ucc_uid","cc_name","cc_start_time","cc_end_time","cc_desc","cc_price"].join(",")
                        }*/
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        resultData.videoCourserData = data.data;
                        cb();
                    }
                );

            },
            //2.课程目录
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_video_course_list + "/vcl_vc_id/"+restfulParams.vc_id,
                        method: 'POST',
                        data: {
                            fields: ["vcl_id","vcl_video_tittle","vcl_video_time","vcl_video"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        resultData.videoCourserListData = data.data;
                        cb();
                    }
                );

            },
            //3.学员评价
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.video_course_comment_user + "/count/1/vcm_vcid/"+restfulParams.vc_id,
                        method: 'GET',
                        /*data: {
                            fields: ["vcl_id","vcl_video_tittle","vcl_video_time"].join(",")
                        }*/
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        resultData.videoCourserCommentCountData = data.count;
                        resultData.videoCourserCommentListData = data.data;
                        cb();
                    }
                );

            },
            //判断是否收藏了该视频课程
            function(cb){

                if(restfulParams.u_id == 0){
                    cb();
                }else{

                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.userSearchCollect + "/uc_uid/"+restfulParams.u_id + "/uc_fid/" +restfulParams.vc_id + "/uc_type/5",
                            method: 'GET'
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }   
    
                            if(data.data.length > 0){
                                resultData.isCollect = true;
                            }else{
                                resultData.isCollect = false;
                            }
    
                            cb();
                        }
                    );
                }

            },
            //2.获取当前地址与机构的距离
            function (cb) {
                var distance = common.GetDistance(lat,lng,resultData.videoCourserData[0].o_longitude,resultData.videoCourserData[0].o_latitude);
                resultData.distance = distance;
                cb();
            },



        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}